package com.huan.partition;

import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

import java.io.IOException;

public class FlowCountMapper extends Mapper<LongWritable, Text,Text, FlowBean> {

    Text k = new Text();
    FlowBean v = new FlowBean();

    @Override
    protected void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {

        //TODO 获取值和切分
        String[] splits = value.toString().split( "\t" );

        //TODO 封装手机号
        k.set( splits[1]);

        //TODO 反方向封装
        //TODO 减去上行流量和下行流量
        long upFlow  = Long.parseLong( splits[splits.length - 3] );
        long downFlow = Long.parseLong( splits[splits.length - 2] );

        //TODO 拿到FlowBean类的方法，赋值
        v.setUpFlow( upFlow );
        v.setDownFlow( downFlow );
        v.set( upFlow,downFlow );

        //TODO 写出
        context.write( k,v );
    }
}
